<?php
require_once  'SiteController.php';
class PostController extends SiteController{
	public function init(){
		parent::init();
	}
	public function indexAction(){
		$this->view->headLink()->appendStylesheet($this->view->baseUrl().'/public/skins/default/css/post.css');
//		//lấy tham số slug
		$slug = $this->getRequest()->getParam('slug');
		$post = $this->_postModel->getPostBySlug($slug);
		$this->view->post = $post;
		if($post['type'] == 'article'){
			//lấy các bài viết liên quan
			$this->view->relatePosts = $this->_postModel->getRelatePosts($post);
			//var_dump($this->view->relatePosts);
			$this->view->relateCategory = $post->findParentRow("Model_Category");
		}
		try{
			if(isset($post->page_title) && $post->page_title != ""){
	    		$this->view->headTitle($post->page_title, "SET");
	    	}else{
				$this->view->headTitle("Sieu thi Cuong Phu chuyen: May in HP 1132, May in HP 1102, May in mau HP, May in Canon 2900, May in da nang Canon");
			}
	    	if(isset($post->page_description) && $post->page_description != ""){
	    		$this->view->headMeta()->appendName("description", $post->page_description);
	    	}else{
				$this->view->headMeta("description", "Sieu thi Cuong Phu chuyen cung cap cac loai may in chinh hang voi gia ca re nhat tren thi truong, may in hp 1132, May in HP 1102, may in mau hp, May in Canon 2900, May in da nang Canon");
			}
			if(isset($post["tag"]) && $post["tag"] != "") {
				$this->view->headMeta()->appendName( "keywords",$post->tag);
			}else{
				$this->view->headMeta("keywords", "may in hp 1132, May in HP 1102, may in mau hp, May in Canon 2900, May in da nang Canon, cung cap may in, may in");
			}
			
		}catch (Exception $ex){
			echo $ex->getMessage();
		}
		
	}
	public function categoryAction(){
		$this->view->headLink()->appendStylesheet($this->view->baseUrl().'/public/skins/default/css/category1.css');
		$id  = $this->getRequest()->getParam("id");
		$currentPage = $this->getRequest()->getParam("page");
		try{
		$category = $this->_categoryModel->getCategoryByID($id);
		$this->view->category = $category;
		$arrPosts = $category->findDependentRowset("Model_Post");
		
		//Đưa danh sách product vào Zend_Paginator để bắt đầu phân trang
        $paginator = Zend_Paginator::factory($arrPosts);
        //Số product trên một trang
        $paginator->setItemCountPerPage(2);
        //Số trang được hiện ra để click
        $paginator->setPageRange(5);
        //vi page lấy về có dạng _p1 nên phải bỏ chữ p đi
        $currentPage = substr($currentPage, 2);
        $paginator->setCurrentPageNumber($currentPage);
        
        //Truyền dữ liệu ra view
        $this->view->arrPosts=$paginator;
		}catch (Exception $ex){
			echo $ex->getMessage();
		}
	}
}
